<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <div id="box"></div>
    </body>
    <script>
        let obj = {
            name: '张三',
            age: 18,
            date: new Date(),
            reg: new RegExp('/^[a-zA-Z]{3,6}$/'),
            fun: function () {
                console.log(123)
            },
        }
        // let n = obj
        // n.name = '李四'
        // console.log(obj, n)
        // let num = 100
        // 1、es6的展开语法
        // let n = { ...obj }
        // n.name = '李四'
        // console.log(n)

        // 2.JSON.parse(JSON.stringify(obj))

        //这个深拷贝方式不会拷贝函数，正则，日期
        // let n = JSON.parse(JSON.stringify(obj))
        // console.log(n)
        // 3.JS中拷贝Array的slice和concat方法【针对数组】Object.assign()
        let yuanlai = [
            1,
            2,
            3,
            4,
            {
                date: new Date(),
                reg: new RegExp('/^[a-zA-Z0-9]{6,12}$/'),
                fun: function () {
                    console.log(888)
                },
            },
            [99, 88],
        ]
        let xinde = yuanlai.slice()
        //不完全是深拷贝，只是拷贝了一层
        xinde.push(5)
        xinde[5][1] = '李四'
        xinde[5].push('王五')
        console.log('yuanlai:', yuanlai)
        console.log('xinde:', xinde)
    </script>
</html>
